#ifndef FCTHREAD_H
#define FCTHREAD_H

#include <Famicom.h>
#include <QAudioOutput>
#include <QThread>


class FcThread:public QThread,public IFcEvent
{

public:
    enum
        {
            EVENT_RELOADROM = 0x1,
            EVENT_SAVE_STATE = 0x2,
            EVENT_RESTORE_STATE = 0x4,
            EVENT_PAUSE = 0x8,
        };
    int EVENT_FLAG = 0;
    int FPS = 0;
    QWidget * uiwindow = nullptr;
    QString filename = "";
    std::fstream* savefs = nullptr;
    QAudioOutput *audio;
    QIODevice *streamOut;
    Famicom* famicom = nullptr;
    FcThread(QWidget * main);
    void SyncLoadRom(QString strFilename);
    void GetFrameBuffer(int32_t* dstbuffer, int size);
    void Input(uint8_t index, uint8_t state);
    //IFcEvent
    virtual bool OnSaveBundleOpen(bool issave)override;
    virtual bool OnSaveBundleClose()override;
    virtual void OnSaveBundleWrite(char* buf, int size)override;
    virtual void OnSaveBundleRead(char* buf, int size)override;
    virtual void OnAudioWrite(short* buf, int size)override;
    void run() override;
};

#endif // FCTHREAD_H
